package com.junko.service.app.impl;

import com.junko.core.base.BaseServiceImpl;
import com.junko.dao.app.UserDao;
import com.junko.model.app.User;
import com.junko.service.app.IUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService extends BaseServiceImpl<User> implements IUserService {
    @Autowired
    private UserDao dao;


    @Override
    public User findByUserName(String userName) {
        if (StringUtils.isEmpty(userName)) {
            return null;
        }
        return dao.findByUserName(userName);
    }

    @Override
    public User findByMobile(String mobile) {
        if (StringUtils.isEmpty(mobile)) {
            return null;
        }
        return dao.findByMobile(mobile);
    }

    @Override
    public User findByIdFetchInfo(Integer id) {
        if (id == null) {
            return null;
        }
        return dao.findByIdFetchInfo(id);
    }

    @Override
    public User findByAccount(String account) {
        User user = findByUserName(account);
        return user != null ? user : findByMobile(account);
    }
}